﻿/******************************************************************************
 * Name         : EchoPacket.cpp
 * Author       : 671643387
 * Date         : 2015年9月21日
 * Description  :
 *****************************************************************************/

#include <memory.h>
#include <dev/base/Runtime.hpp>
#include "EchoPacket.hpp"
using namespace sxr::common;

EchoPacket::EchoPacket(int id)
: Packet(id, sizeof(payload_), (char*)&payload_)
{
    memset(&payload_, 0, sizeof(payload_));
    payload_.head.id = PACKET_ID_ECHO;
    payload_.head.size = sizeof(payload_);
}

EchoPacket::~EchoPacket()
{

}

bool EchoPacket::execute(Player* player)
{
    return EchoPacketHandler::execute(this, player);
}

void EchoPacket::copy(const char* msg)
{
    size_t msgLen = __DV_MIN(strlen(msg), sizeof(payload_.message) - 1);
    memcpy(&payload_.message, msg, msgLen);
    payload_.message[msgLen] = '\0';
}